const enterpriseVue = new Vue({
  el: "#app",
  data() {
    return {
      pickerOptions: pickerOptions,
      rules: {
        Brand_Name: [
          {
            required: true,
            message: "请输入品牌名称",
            trigger: "blur",
          },
        ],
      },
      form: {
        Path: "",
        Group_Tab_Name: "",
        Group_Tab_SerialNumber: "",
        Group_Tab_Type: "",
        Group_Tab_Value: "",
        Group_Tab_Sort: "",
      },
      loading: false,
    };
  },
  mounted() {
    const Group_Tab_SerialNumber = sessionStorage.getItem(
      "Group_Tab_SerialNumber"
    );
    this.getData(Group_Tab_SerialNumber);
  },
  methods: {
    getData(Primary_Key) {
      const _this = this;
      $.ajax({
        headers: {
          AccessToken: $.cookie("token"), //会将数据转换为query string
        },
        // url: DomainName + `/getInquiryIDOriginal?token=${$.cookie('token')}`,
        url: "https://service.kdddy.cn/donghui/generalBusiness/generalQueryByTableNameWithOriginal",
        type: "POST",
        data: {
          Data: "group_tab", //表名
          Condition:
            "Row_Status='0' and Group_Tab_SerialNumber = '" + Primary_Key + "'",
        },
        //   data: { Data: 'group_tab',
        //   Primary_Key,
        //   Primary_Key_Name:'Group_Tab_SerialNumber',
        //   isNullEnterprise: true
        //  },
        success: function (res) {
          console.log("根据品牌流水获取结果", res);
          _this.form = res[0];
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false;
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href =
              "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
      });
    },
    submitForm(formName) {
      let _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const { add, modify } = _this.deal();
          let data = {};
          if (add == null) {
            data = {
              Data: JSON.stringify({ Modify: { group_tab: [modify] } }),
            };
          } else {
            data = {
              Data: JSON.stringify({
                Modify: { group_tab: [modify] },
                Add: { group_tab: [add] },
              }),
            };
          }
          _this.loading = true;
          $.ajax({
            // url: DomainName + "/getEditAction?token=" + $.cookie("token"),
            url: "https://service.kdddy.cn/donghui/clientOperation/generalSaveForClient",
            type: "POST",
            data,
            success: function (res) {
              console.log("提交结果", res);
              _this.$message.success("提交成功");
              window.history.go(-1);
            },
            error: function () {
              _this.$message.error("操作失败，请稍后再试");
            },
            complete: function (XMLHttpRequest) {
              _this.loading = false;
              if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                window.parent.document.location.href =
                  "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
              }
            },
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    deal() {
      const modify = deepClone(this.form);
      return { add: null, modify };
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
});
